﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// search_photo_more 的摘要说明
    /// </summary>
    public class search_photo_more : IHttpHandler
    {
        protected int totalCount = 0;
        protected int pages = 1;
        public void ProcessRequest(HttpContext context)
        {
            string keyword = Utils.ToHtml(DTRequest.GetQueryString("keyword"));
            int pages = DTRequest.GetQueryInt("page", 1);

            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");

            //获取企业信息
            BLL.company qg_bll = new BLL.company();
            DataSet qg_ds = qg_bll.GetList(10, pages, "title like '%" + keyword + "%' or pro_remark like '%" + keyword + "%' and status=1", "sort_id desc,group_id desc,id asc", out this.totalCount);
            //如果记录存在
            int xx_total_page = this.totalCount / 10;
            strTxt.Append("\"total_page\":" + xx_total_page.ToString());
            if (qg_ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append(",\"company_list\":[");
                for (int i = 0; i < qg_ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = qg_ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    if (dr["logo"].ToString().Contains("shicaiquanzi"))
                    {
                        if (dr["logo"].ToString().Contains("http://")) { strTxt.Append(",\"img_url\":\"" + dr["logo"] + "\""); }
                        else { strTxt.Append(",\"img_url\":\"http://" + dr["logo"] + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"img_url\":\"http://pic.shicaiquanzi.com" + dr["logo"] + "\"");
                    }
                    strTxt.Append(",\"pro_remark\":\"" + Microsoft.JScript.GlobalObject.escape(dr["pro_remark"].ToString()) + "\"");
                    strTxt.Append(",\"group_id\":" + dr["group_id"]);
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < qg_ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                strTxt.Append(",\"company_list\":[]");
            }


            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}